//
//  HCMineContentView.m
//  HappyChildren
//
//  Created by WillyZhao on 2016/12/27.
//  Copyright © 2016年 WillyZhao. All rights reserved.
//

#import "HCMineContentView.h"

#import "HCMineContentTableViewCell.h"

@interface HCMineContentView () <UITableViewDelegate,UITableViewDataSource> {
    NSArray *dataContentArray;
}

@end

@implementation HCMineContentView

-(instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self initSubViewsCustomFrame:frame];
    }
    return self;
}

-(void)initSubViewsCustomFrame:(CGRect)frame {
    
    dataContentArray = @[
  @[@"happy_mine_loveHeart",@"我的预约",@"YBKAccountManagerVC"],
  @[@"mine_vip_logo",@"我的会员",@"HCVIPViewController"],
  @[@"happy_mine_littleTree",@"成长相册",@"YBKBenifitTicketVC"],
  @[@"happy_mytable_mine",@"我的兑换",@"YBKBenifitTicketVC"],
  @[@"happy_mine_stores",@"积分商城",@"YBKMyCollectionVC"],
  @[@"happy_mine_service",@"服务中心",@"YBKMineHelpVC"],
  @[@"happy_mine_score",@"欢迎评分",@"YBKSuggestFeedBackVC"],
  @[@"happy_mine_fiveStar",@"我的收藏",@"YBKSuggestFeedBackVC"],
  @[@"mine_address_img",@"地址管理",@"HCAddressManagerController"]];
    
    self.contentTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height + 34)];
    self.contentTableView.backgroundColor = [UIColor whiteColor];
    self.contentTableView.delegate= self;
    self.contentTableView.dataSource = self;
    self.contentTableView.rowHeight = 44;
    self.contentTableView.scrollEnabled = NO;
    self.contentTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self addSubview:self.contentTableView];
    [self.contentTableView registerNib:[UINib nibWithNibName:@"HCMineContentTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"hcmine"];
    
}

- (void)setLabel:(NSString *)vipcardNum isVip:(BOOL)isvip {

    NSIndexPath *indexpath = [NSIndexPath indexPathForRow:1 inSection:0];
    HCMineContentTableViewCell *cell = [self.contentTableView cellForRowAtIndexPath:indexpath];
    if (!isvip) {
        
        cell.noVIPLabel.text = @"非会员";
    }
    else {
    
        cell.noVIPLabel.text = vipcardNum;
    }
}

#pragma UITableView代理
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 6;
    }else if (section == 1) {
        return 1;
    }else if (section == 2) {
        return 2;
    }else {
        return 3;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    HCMineContentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"hcmine" forIndexPath:indexPath];
    if (!cell) {
        cell = [[HCMineContentTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"hcmine"];
    }
    [cell setCellModel:dataContentArray indexPath:indexPath];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
   
    if (section == 0) {
        return 0;
    }else{
        return 10;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if ([self.delegate respondsToSelector:@selector(hcMineContentViewCellClickedIndexPath:)]&&self.delegate) {
        [self.delegate hcMineContentViewCellClickedIndexPath:indexPath];
    }
}

@end
